package com.base.cn.platform.os.controller.op.coupon;

import com.base.cn.platform.os.common.controller.BaseController;
import com.base.cn.platform.os.common.utils.ObjectUtils;
import com.base.cn.platform.os.entity.op.coupon.OpCouponShop;
import com.base.cn.platform.os.service.op.coupon.OpCouponShopBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 * 优惠券关联商品Controller
 *
 * @author s.li
 * @date 2019/05/14
 */
@RestController
@RequestMapping("/manage/op")
public class OpCouponShopController extends BaseController {
    @Autowired
    private OpCouponShopBiz opCouponShopBiz;

    /**
     * 获取载一个优惠券的商品数据
     * @param couponId
     * @return
     */
    @RequestMapping("/showCouponShopData")
    public List<OpCouponShop> showCouponShopData(@RequestParam("couponId")BigDecimal couponId){
        List<OpCouponShop> couponShopList = opCouponShopBiz.findCouponShopList(couponId);
        if(ObjectUtils.isNotEmpty(couponShopList)){
            couponShopList.forEach(e->{
                e.getShop().setCourse(null);
                e.getShop().setExam(null);
                e.getShop().setBook(null);
                e.getShop().setMember(null);
                e.getShop().setQa(null);
            });
        }
        return couponShopList;
    }
}
